<?php
/**
 * 工资核算模型
 */

namespace app\common\model;

use think\model\concern\SoftDelete;

class SalaryLog extends Model
{
    use SoftDelete;
    public $softDelete = true;
    protected $name = 'salary_log';
    protected $autoWriteTimestamp = true;

    //可搜索字段
    protected $searchField = ['staff_id', 'department_id',];
    public $whereField = ['staff_id','status','salary_time'];
    //状态获取器
    public function getStatusTextAttr($value, $data)
    {
        return self::BOOLEAN_TEXT[$data['status']];
    }//工资日期获取器

    public function getSalaryTimeAttr($value)
    {
        return date('Y-m', $value);
    }
    public function setSalaryTimeAttr($value)
    {
        return strtotime($value);
    }


    //附件获取器
    public function getFileAttr($value)
    {
        return json_decode($value, true);
    }

//附件修改器
    public function setFileAttr($value)
    {
        return json_encode($value);
    }

    //关联员工表
    public function staff()
    {
        return $this->belongsTo(Staff::class,'staff_id','id');
    }

    //关联职位表
    public function department()
    {
        return $this->belongsTo(Department::class);
    }

    public function basicSalary()
    {
        return $this->belongsTo(BasicSalary::class,'staff_id','staff_id');
    }
    public function insure()
    {
        return $this->belongsTo(Insure::class,'insure_id','id');
    }
}
